﻿using System;
using System.Collections.Generic;
using System.Text;
using ECC_EXT_Entity;
using NHibernate;
using NHibernate.Criterion;

namespace ECC_EXT_DAO.Dao
{
    public class OFFCategoryDao:DaoBase
    {
        public void SaveOrUpdate(OFFCategoryEntity _offCategoryEntity)
        {
            using (ISession session = this.SessionFactory.OpenSession())
            {
                session.BeginTransaction();
                session.SaveOrUpdate(_offCategoryEntity);
                session.Transaction.Commit();
            }
        }

        public OFFCategoryEntity GetById(string id)
        {
            using (ISession session = this.SessionFactory.OpenSession())
            {
                
                return
                    session.Get<OFFCategoryEntity>(long.Parse(id));

            }
        }

        public IList<OFFCategoryEntity> Search(OFFCategoryEntitySearch _offCategoryEntitySearch)
        {
            using (ISession session = this.SessionFactory.OpenSession())
            {
                ICriteria criteria =
                    session.CreateCriteria<OFFCategoryEntity>();

                criteria.Add(Restrictions.Between("RecordDate",
                                                  _offCategoryEntitySearch.RecordDateFrom,
                                                  _offCategoryEntitySearch.RecordDateTo.AddDays(1)));

                if (_offCategoryEntitySearch.RecordUser != null)
                    criteria.Add(Restrictions.Like("RecordUser",
                                                 _offCategoryEntitySearch.RecordUser,
                                                 MatchMode.Anywhere));


                //criteria.Add(Restrictions.Eq("CategoryFullName", _mailLogEntity.CategoryFullName));
                return
                criteria.List<OFFCategoryEntity>();
            }
        }

        public IList<OFFCategoryEntity> Search()
        {
            using (ISession session = this.SessionFactory.OpenSession())
            {
                ICriteria criteria =
                    session.CreateCriteria<OFFCategoryEntity>();
                //_mailLogEntitycriteria.Add(Restrictions.Eq("MailNo", _mailLogEntity.MailNo));
                //criteria.Add(Restrictions.Eq("CategoryFullName", _mailLogEntity.CategoryFullName));
                return
                criteria.List<OFFCategoryEntity>();
            }
        }

        public IList<OFFCategoryEntity> Search(OFFCategoryEntity _offCategoryEntity)
        {
            using (ISession session = this.SessionFactory.OpenSession())
            {
                ICriteria criteria =
                    session.CreateCriteria<OFFCategoryEntity>();
                //_mailLogEntitycriteria.Add(Restrictions.Eq("MailNo", _mailLogEntity.MailNo));
                //criteria.Add(Restrictions.Eq("CategoryFullName", _mailLogEntity.CategoryFullName));
                return
                criteria.List<OFFCategoryEntity>();
            }
        }
    }

    public class OFFCategorySearchDto
    {
        public string RecordDateFrom { get; set; }
        public string RecordDateTo { get; set; }

        public string RecordUser { get; set; }
    }
}
